GitHub

您所在的位置:网站首页 python urljoin GitHub

GitHub

2023-04-03 09:41| 来源: 网络整理| 查看: 265

EdgeGrid for Python

This library implements an authentication handler for HTTP requests using the EdgeGrid authentication scheme.

Prerequisites

Before you begin, you need to Create authentication credentials in Control Center.

Download the Python release compatible with your operating system at https://www.python.org/downloads/.

Python 2 is no longer supported by the Python Software Foundation. However, if you're still using it, you can follow the Python 2 steps.

Install

Install Python.

python setup.py install

Install the developer libraries for Python, SSL and FFI.

sudo apt-get install ibssl-dev libffi-dev python-dev

Install the edgegrid-python authentication handler.

pip install edgegrid-python Make an API call

To use Akamai APIs, you need the values for the tokens from your .edgerc file.

>>> import requests >>> from akamai.edgegrid import EdgeGridAuth >>> from urllib.parse import urljoin >>> baseurl = 'https://akaa-WWWWWWWWWWWW.luna.akamaiapis.net/' >>> s = requests.Session() >>> s.auth = EdgeGridAuth( client_token='ccccccccccccccccc', client_secret='ssssssssssssssssss', access_token='aaaaaaaaaaaaaaaaaaaaa' ) >>> result = s.get(urljoin(baseurl, '/diagnostic-tools/v2/ghost-locations/available')) >>> result.status_code 200 >>> result.json()['locations'][0]['value'] Oakbrook, IL, United States ...

This is an example of an API call to List available edge server locations. Change the baseurl element to reference an endpoint in any of the Akamai APIs.

Alternatively, your program can read the credential values directly from the .edgerc.

>>> import requests >>> from akamai.edgegrid import EdgeGridAuth, EdgeRc >>> from urllib.parse import urljoin >>> edgerc = EdgeRc('~/.edgerc') >>> section = 'default' >>> baseurl = 'https://%s' % edgerc.get(section, 'host') >>> s = requests.Session() >>> s.auth = EdgeGridAuth.from_edgerc(edgerc, section) >>> result = s.get(urljoin(baseurl, '/diagnostic-tools/v2/ghost-locations/available')) >>> result.status_code 200 >>> result.json()['locations'][0]['value'] Oakbrook, IL, United States ...

NOTE: If your .edgerc file contains more than one credential set, use the section argument to specify which section contains the credentials for your API request.

Virtual environment

To test in a virtual environment, run:

$ python3 -m venv venv $ . venv/bin/activate $ pip install -r requirements.txt $ python -m unittest discover Python 2 steps

Python 2.7 is no longer supported by the Python Software Foundation, but we recognize that some developers continue to use it. If you're using Python 2.7 with EdgeGrid, follow these steps.

To upgrade the cryptography package, first run:

pip install --upgrade 'cryptography


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3